<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>用户新增</title>
		
		<!-- 导入easyui所需要的5个文件开始 -->
		<script type="text/javascript" src="js/jquery-easyui-1.4.5/jquery.min.js" ></script>
		<script type="text/javascript" src="js/jquery-easyui-1.4.5/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="js/jquery-easyui-1.4.5/locale/easyui-lang-zh_CN.js"></script>
		<link rel="stylesheet" href="js/jquery-easyui-1.4.5/themes/default/easyui.css" />
		<link rel="stylesheet" href="js/jquery-easyui-1.4.5/themes/icon.css" />
		<!-- 导入easyui所需要的5个文件结束 -->
		
		<script type="text/javascript" src="js/common.js" ></script>
		
		<style>
			#scott-div{
				padding:10px;
			}
			.form-row{
				margin-top:5px;
			}
		</style>
	</head>
<body>

	<!-- http://localhost:8080/scott-easyui/user-add.html -->
	
	<div id="scott-div" class="easyui-panel" style="width:250px;height:auto;" title="用户新增">
		<form id="scott-form" method="post">
			<div class="form-row">
				<label for="userName">用户名:</label>
				<input class="easyui-validatebox"  style="width:150px" type="text" name="userName" data-options="required:true" />
		    </div>
		    
		    
		    <div class="form-row">
				<label for="userAge">年&nbsp;&nbsp;&nbsp;龄:</label>
				<input class="easyui-numberbox" type="text" name="userAge" style="width:155px" data-options="required:true" />
		    </div>
		    
		    <div class="form-row" style="text-align: center;">
		    		<a class="easyui-linkbutton" data-options="iconCls: 'icon-ok'" onclick="add();">提交</a>
		    </div>
		    
    
		</form>
	</div>
	

</body>
	<script>
		function add(){
			$('#scott-form').form('submit',{
				url: getPath()+'/user/add', 
		        	//表单提交前的回调函数 
		        onSubmit: function () {        
		        	  //验证通过返回true 否则返回false 调用form表单的validate方法 不需要参数
		          var jieguo = $('#scott-form').form('validate');
		          if (jieguo == false) { 
		        			//如果验证不通过，返回false终止表单提交 
		        	  		$.messager.show({
		        	  			title:'提示...',
		        	  			msg:'亲 验证没有通过 不能提交表单...'
		        	  		});
		        			return false;
		          } 
		          return jieguo; 
		        }, 
		        success:function(data){
		        		var jsonData = eval('('+data+')');
		        		
		        		var code =jsonData.code;
		        		if(code == 'success'){
		        			window.location.href='user-list.html';
		        		}
		        }
			});
			
		}
	</script>
</html>